// 异步路由需要权限验证
import Student_Detection_List from '@/views/detection/student_detection_list'
import Batch from '@/views/detection/batch'
import SubmitInfo from '@/views/detection/submitinfo'


const routes = [{
    name: "detection",
    path: "/detection",
    redirect: '/detection/student_detection_list',
    meta: {
        title: "核酸检测",
        icon: "el-icon-menu",
        type: "menu"
    },
    children: [{
        name: "batch",
        path: "/detection/batch",
        component: Batch,
        meta: {
            title: "周次管理",
            icon: "el-icon-menu"
        }
    }, {
        name: "submitinfo",
        path: "/detection/submitinfo",
        component: SubmitInfo,
        meta: {
            title: "提交情况",
            icon: "el-icon-menu"
        }
    }, {
        name: "student_detection_list",
        path: "/detection/student_detection_list",
        component: Student_Detection_List,
        meta: {
            title: "结果导出",
            icon: "el-icon-menu"
        }
    }, ]
}]

// 按照角色生成路由表
export function generateRoleRouter(role) {
    function getRouter(routes, role) {
        routes = routes.map(item => {
            // 有权限
            if ((item.meta.role && item.meta.role.includes(role)) || !item.meta.role) {
                if (item.children) {
                    const children = getRouter(item.children, role)
                    children.length === 0 ? (delete item.children) : (item.children = children)
                }
                return item
            }
            return null
        })
        return routes.filter(item => item !== null)
    }
    return getRouter(routes, role)
}

export default routes